package com.jdbc.transaction_xml;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

public class BookShopServiceImpl implements BookShopService {

	@Autowired
	private BookShopDao bookShopDao;
	
	public void setBookShopDao(BookShopDao bookShopDao) {
		this.bookShopDao = bookShopDao;
	}

	// 添加事务注解
	public void purchase(String username, String isbn) {
		// 获取书的单价
		int price = bookShopDao.findBookPriceByIsbn(isbn);

		// 更新书的库存
		bookShopDao.updateBookStock(isbn);

		// 更新用户余额
		bookShopDao.updateUserAccount(username, price);

	}

}
